package top.jnaw.jee.platform.model;

import com.alibaba.fastjson.JSONArray;
import java.io.File;
import top.jnaw.jee.platform.Consts;
import top.jnaw.jee.utils.Excel;
import top.jnaw.jee.utils.Log;
import top.jnaw.jee.utils.ModelResult;

/**
 * Copyright (C) 2018 版权所有。 <p> 文件名： 文件功能描述：
 *
 * @author lc  2018/7/20 14:46 创建内容： <p> <p> 修改标识： 修改原因：
 */
public class CallBack {

  private Callback mCallback;

  public CallBack(Callback callback) {
    this.mCallback = callback;
  }


  public ModelResult foo(String url, int sheetIndex) {
    ModelResult result = new ModelResult();
    try {
      // [Neo] .step 1
      Excel excel = new Excel(new File(url));
//      Excel excel = new Excel(new File("C:\\Users\\Administrator\\Desktop\\综合技能1.xlsx"));

      JSONArray json = excel.getData();

      if (null != json && json.size() > 0) {
        JSONArray sheet = json.getJSONObject(sheetIndex).getJSONArray("data");

        int row = sheet.size();
        for (int i = 0; i < row; ++i) {
          // [Neo] .step 2
          JSONArray r = sheet.getJSONArray(i);

          // [Neo] .step 3
          if (!mCallback.after(r)) {
            Log.i("第" + i + "行数据导入失败");
          }
        }
        result.setResult(Consts.Result.kSuccess);
      }

    } catch (Exception e) {
      e.printStackTrace();
    }

    return result;
  }

  public interface Callback {

    boolean after(JSONArray row);
  }


}